package com.neu.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.neu.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 *
 *
 */

@Schema(description = "软件因素")
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("project_swf")
public class SWF extends BaseEntity{

    @TableId(type= IdType.ASSIGN_ID)
    private String projectId;

    private Integer Period;//主要是早期（0）、中期（1）、晚期（2）、交付后运营（3）四个阶段
    private String Business;
    private String AppType;
    private Integer QualityDistributed;
    private Integer QualityPerformance;
    private Integer QualityReliability;
    private Integer QualityMultiple;
    private Float swf;
    private int progress;//0代表未完成、1代表已完成


    public int getProgress() {
        return progress;
    }

    public void setProgress(int progress) {
        this.progress = progress;
    }



    /**
     *
     * 规模调整因子
     * 0：在估算早期（如概算，预算阶段）,规模调整因子取值通常为1.39;
     * 1：在估算中期（如投标，项目计划阶段）,规模调整因子取值通常为1.21:
     * 2：在估算晚期（如需求分析阶段）,规模调整因子取值通常为1.10;
     * 3：在项目交付后及运维阶段，规模调整因子取值为通常1.00.
     */
    public Float calcSF(){
        Float SF;
        switch (this.Period){
            case 0:
                SF = 1.39F;
                break;
            case 1:
                SF = 1.21F;
                break;
            case 2:
                SF = 1.1F;
                break;
            case 3:
                SF = 1.0F;
                break;
            default:
                SF = 1.0F;
                break;
        }
        return SF;
    }

    /**
     *
     *
     */
    public Float calcBD(){
        Float BD;
        /*
        [0, 1, 0.9958, 0.4662, 0.2839, 0.4028]
         */
        switch (this.Business){
            case "电子政务":
                BD = 1.0F;
                break;
            case "金融":
                BD = 2.0F;
                break;
            case "电信":
                BD = 1.9958F;
                break;
            case "制造":
                BD = 1.4662F;
                break;
            case "能源":
                BD = 1.2839F;
                break;
            case "交通":
                BD = 1.4028F;
                break;
            default:
                BD = 1.45F;
        }
        return BD;
    }

    public Float calcAT(){
        Float AT;

        switch (this.AppType){
            case "业务处理":
                AT = 1.0F;
                break;
            case "应用集成":
                AT = 1.2F;
                break;
            case "科技":
                AT = 1.2F;
                break;
            case "多媒体":
                AT = 1.3F;
                break;
            case "智能信息":
                AT = 1.7F;
                break;
            case "系统":
                AT = 1.7F;
                break;
            case "通信控制":
                AT = 1.9F;
                break;
            case "流程控制":
                AT = 2.0F;
                break;
            default:
                AT = 1.0F;
        }
        return AT;
    }

    public Float calcQR(){
        Integer t = 0;
        t += QualityDistributed;
        t += QualityMultiple;
        t += QualityPerformance;
        t += QualityReliability;

        return (float) (1.0F + (0.025*t));
    }

    public Map<String, Float> calc(){
        Map<String, Float> map = new HashMap<>();

        map.put("at",this.calcAT());
        map.put("bd",this.calcBD());
        map.put("sf",this.calcSF());
        map.put("qr",this.calcQR());
        map.put("swf",this.calcAT()*this.calcBD()*this.calcSF()*this.calcQR());
        this.swf = map.get("swf");
        return map;
    }


}
